package Jets.ui
{
   import flash.display.DisplayObjectContainer;
   import flash.geom.Rectangle;
   import Jets.display.JContainer;
   
   public class JProgressBar extends JContainer
   {
      
	   protected var _bar:JPanel;
	   protected var _forebar:JPanel;
	  
	   private var _value:Number = 0;
	   private var _max:Number = 1;
	   
      public function JProgressBar(parent:DisplayObjectContainer=null, cx:Number=0, cy:Number=0) 
	  {
         super(parent,cx,cy);
      }

      override protected function init() : void 
	  {
         super.init();
         setSize(100,10);
      }
      
      override protected function addChildren() : void 
	  {
         this._bar = new JPanel();
         this._forebar = new JPanel();
         addChild(this._bar);
         addChild(this._forebar);
      }
      
	  public function get backBar():JPanel
	  {
		  return _bar;
	  }
	  
	  public function get foreBar():JPanel
	  {
		  return _forebar;
	  }
	  
	  
      private function update() : void 
	  {
         this._bar.scrollRect = new Rectangle(0,0,this._bar.width * this._value / this._max,this._bar.height);
      }
      
      override public function draw() : void 
	  {
         super.draw();
         this._bar.setSize(this.width,this.height);
         this.update();
      }
      
      public function set maximum(value:Number) : void 
	  {
         this._max = value;
         this._value = Math.min(this._value,this._max);
         this.update();
      }
      public function get maximum() : Number 
	  {
         return this._max;
      }
      
      public function set value(value:Number) : void 
	  {
         this._value = Math.min(value,this._max);
         this.update();
      }
      public function get value() : Number 
	  {
         return this._value;
      }
   }
}
